package logic

import (
	"context"
	"gorm.io/gorm"
	"product/model/mysql"

	"product/productrpc/internal/svc"
	"product/productrpc/productrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClassUpdateLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClassUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClassUpdateLogic {
	return &ClassUpdateLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 商品分类修改
func (l *ClassUpdateLogic) ClassUpdate(in *productrpc.ClassUpdateRequest) (*productrpc.ClassUpdateResponse, error) {
	// todo: add your logic here and delete this line
	class := mysql.Class{
		Model:  gorm.Model{ID: uint(in.Id)},
		UserId: in.UserId,
		Name:   in.Name,
	}
	mysql.DB.Debug().Where("id=?", in.Id).Updates(&class)
	return &productrpc.ClassUpdateResponse{
		Id: int64(class.ID),
	}, nil
}
